package Class_Object.继承;

public class Dog extends Animal{
    public int id = 123;
    public String name = "小白";
    public Dog(String name, int age) {
        super(name, age);
        System.out.println("Dog调用父类的构造方法,初始化成员");

    }

    @Override
    public String toString() {
        return "Dog{" +
                "id=" + id +
                ", name='" + name + '\'' +
                '}';
    }

    public Dog(String name, int age, int id) {
        super(name, age);
        this.id = id;
    }
    public Dog() {

    }

    public void bark(){
        System.out.println(this.name+"正在狗叫");
    }


    static {
        System.out.println("Dog的静态代码块");
    }
    {
        System.out.println("Dog的实例代码块");
    }

    public static void main(String[] args) {
//        Dog dog = new Dog();
//        System.out.println(dog.name);//直接访问继承下来的name
//        System.out.println(dog.id);//直接访问dog自身的属性id
//        dog.eat();//使用父类继承下来的eat方法
//        dog.bark();//使用dog自身的bark方法
        Dog dog = new Dog("小白",12);
        System.out.println("=============");
        Dog dog1 = new Dog("小黑",12);
        System.out.println(dog1.toString());


    }
}
 class Cat extends Animal{
     public Cat(String name, int age) {
         super(name, age);//这个是调用父类的有俩个参数的构造方法
         System.out.println("Cat调用父类的构造方法,初始化成员");
     }

     public void miao(){
         System.out.println(this.name+"正在猫叫");
     }
     static {

     }

}
class Animal {
    //下面是俩个类共同的特点,我们把类的共性进行抽取,从而实现代码的复用效果
    //继承是 is a 的关系
    public String name = "小黑";
    public int age;
    public void eat(){
        System.out.println(this.name+"正在吃饭!");
    }

    public Animal() {
        //无参构造方法
    }
    public Animal(String name, int age) {
        this.name = name;
        this.age = age;
        System.out.println("animal的构造方法");
    }
    static {
        System.out.println("animal的静态代码块");
    }
    {
        System.out.println("animal的实例代码块");
    }
}
